package com.icbci.process.controller;

import com.icbci.process.pojo.Process;
import com.icbci.process.pojo.UserInfo;
import com.icbci.process.service.ProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.Date;
import java.util.List;

@Api("待办推送入口类")
@RestController
public class TestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ProcessService processService;

    @ApiOperation(value = "待办推送", tags = "手动推送待办", response = String.class)
    @GetMapping("/push")
    public String pushMessage(){

        for (int i = 0; i <2000; i++) {
            Process process = Process.builder().processId(i)
                    .processInfo("待办" + i)
                    .processTime(new Date())
                    .processUser("zpj" + i).build();
            //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
            rabbitTemplate.convertAndSend("TestDirectExchange", "TestRouteKey", process);
        }
        return "ok";
    }
    @ApiOperation(tags = "获取流程信息" ,value = "获取待办" ,response = List.class)
    @GetMapping("/getProcess")
    public List<Process> findProcess(){
        return processService.findProcess();
    }

    @ApiOperation(tags = "获取用户信息" ,value = "查询用户" ,response = List.class)
    @GetMapping("/getUser")
    public List<UserInfo> findUser(){
        return processService.findUserInfo();
    }

}
